-- 配置 cmp 插件
return {
    "hrsh7th/nvim-cmp",
  dependencies = {
    "hrsh7th/cmp-buffer",   -- buffer 补全
    "hrsh7th/cmp-path",     -- 文件路径补全
    "hrsh7th/cmp-cmdline",  -- 命令行补全
    "hrsh7th/cmp-nvim-lsp",
    "L3MON4D3/LuaSnip",
--    "hrsh7th/cmp-nvim-lua",
--    "saadparwaiz1/cmp_luasnip",
--    "hrsh7th/cmp-calc",
--    "saadparwaiz1/cmp_luasnip",
--	"hrsh7th/cmp-calc",
	"hrsh7th/cmp-emoji",
--	"hrsh7th/cmp-git",

  },
  config = function()
--		local has_words_before = function()
--			unpack = unpack or table.unpack
--			local line, col = unpack(vim.api.nvim_win_get_cursor(0))
--			return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
--		end
    local cmp = require('cmp')

    -- 配置 cmp 补全源
    cmp.setup({
--      completion = {
--        completeopt = 'menu,menuone,noinsert',  -- 设置补全选项
--      },
--      snippet = {
--        expand = function(args)
--          vim.fn["vsnip#anonymous"](args.body)  -- 如果使用 vsnip 插件可以添加
--        end,
--      },

        snippet = {
            expand = function(args)
                require('luasnip').lsp_expand(args.body)
            end,
        },
      mapping = {
        -- 插入模式下的快捷键
        ["<Tab>"] = function(fallback)
            if cmp.visible() then
                cmp.select_next_item()
            else
                fallback()
            end
        end,
        ["<S-Tab>"] = function(fallback)
            if cmp.visible() then
                cmp.select_prev_item()
            else
                fallback()
            end
        end,
       ['<c-j>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),  -- 下一个补全项
       ['<c-k>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),  -- 上一个补全项


        ["<up>"] = cmp.mapping.scroll_docs(-4),        -- Ctrl + b 向上滚动补全文档
        ["<down>"] = cmp.mapping.scroll_docs(4),         -- Ctrl + f 向下滚动补全文档
        ["<C-Space>"] = cmp.mapping.complete(),        -- Ctrl + Space 手动触发补全
        ["<C-e>"] = cmp.mapping.abort(),              -- Ctrl + e 放弃补全
        ['<CR>'] = cmp.mapping.confirm({ select = true }),  -- 回车确认补全
      },
      sources = {
        { name = 'buffer' },    -- 通过 buffer 内容获取补全
        { name = 'path' },      -- 文件路径补全
        { name = 'emoji' },      -- emoji 表情补全
        { name = 'cmdline' },   -- 命令行补全
        { name = 'nvim_lsp' },   -- lsp 补全
        { name = 'luasnip' },   -- lsp 补全
      },
    })
    
  -- 命令模式下也能补全
  -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline({ '/', '?' }, {
    mapping = cmp.mapping.preset.cmdline(),
    sources = {
      { name = 'buffer' }
    }
  })
  -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources({
      { name = 'path' },
      { name = 'cmdline' }
    }),
    matching = { disallow_symbol_nonprefix_matching = false }
  })
        end
}
